﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ApplicationGenerator.Versions.BusinessLogic;
using System.Threading;
using WCFS;

/// <summary>
/// Summary description for WebWorkflowManager
/// </summary>
public class WebWorkflowManager
{

    #region Variables

    private static WebWorkflowManager _instance;
    private static object _syncObj = new Object();
    private static object _syncObj_creation = new Object();
    private static object _syncObj_goAhead = new Object();
    private static object _syncObj_showPage = new Object();
    private static ProcessService _service = new ProcessService();

    #endregion

    #region Construction

    private WebWorkflowManager()
    {
    }

    #endregion

    #region Contract Methods

    public void GoAhead(Guid _workflowType, int _instanceId)
    {
        lock (_syncObj_creation)
        {
            _service.GoAhead(_workflowType, _instanceId);
        }
    }

    public void CreateWorkflow(Guid id, int instanceId)
    {
        lock (_syncObj_creation)
        {
            _service.CreateWorkflow(id, instanceId);
        }
    }

    public WCFS.PROCESS_STATE IsNewPageToDisplay(Guid id, int instanceId)
    {
        return _service.IsNewPageToDisplay(id, instanceId);
    }

    public VersionInfo GetPageToDisplay(Guid _id, int _instanceId)
    {
        lock (_syncObj_showPage)
        {
            return _service.GetPageToDisplay(_id, _instanceId);
        }
    }

    /// <summary>
    /// This method is reposible for retrieving (or creating) single instance of this class.
    /// </summary>
    /// <param name="response"></param>
    /// <returns></returns>
    public static WebWorkflowManager GetInstance()
    {
        lock (_syncObj)
        {
            if (_instance == null)
            {
                _instance = new WebWorkflowManager();
            }

            return _instance;
        }
    }

    #endregion
}

